
(function () {
    var r = new RegExp("(^|(.*?\\/))(include-lib\\.js)(\\?|$)"),
        s = document.getElementsByTagName("script"), targetScript;
    for (var i = 0; i < s.length; i++) {
        var src = s[i].getAttribute("src");
        if (src) {
            var m = src.match(r);
            if (m) {
                targetScript = s[i];
                break;
            }
        }
    }

    //版本号,用于官网标题处版本号 
    window.marsgis_version = "2.1.1"

 
    // cssExpr 用于判断资源是否是css
    var cssExpr = new RegExp("\\.css");

    function inputLibs(list) {
        if (list == null || list.length == 0) {return;}

        for (var i = 0, len = list.length; i < len; i++) {
            var url = list[i];
            if (cssExpr.test(url)) {
                var css = '<link rel="stylesheet" href="' + url + '">';
                document.writeln(css);
            } else {
                var script = '<script type="text/javascript" src="' + url + '"><' + "/script>";
                document.writeln(script);
            }
        }
    }

    //加载类库资源文件
    function load() {
        var arrInclude = (targetScript.getAttribute("include") || "").split(",");
        var libpath = (targetScript.getAttribute("libpath") || "");

        if (libpath.lastIndexOf("/") != libpath.length - 1)
            {libpath += "/";}

        var libsConfig = {
            "jquery": [
                libpath + "jquery/jquery-2.1.4.min.js"
            ],
            "layer": [
                libpath + "layer/theme/default/layer.css",
                libpath + "layer/theme/retina/retina.css",
                libpath + "layer/theme/mars/layer.css",
                libpath + "layer/layer.js"
            ],
            "haoutil": [
                libpath + "hao/haoutil.js",
                libpath + "hao/loading/loading.css",
                libpath + "hao/loading/loading.js"
            ],
            "turf": [
                libpath + "turf/turf.min.js"
            ],
            "toast": [
                libpath + "toast/snackbar.css",
                libpath + "toast/material.css",
                libpath + "toast/snackbar.min.js"
            ],

            "yjs": [//三维地球“主库”
                libpath + "cesiumjs/Cesium/Widgets/widgets.css", //cesium
                libpath + "cesiumjs/Cesium/Cesium.js",
                libpath + "cesiumjs/plugins/compatible/version.js", //cesium版本兼容处理
                // libpath + "cesiumjs/yjs3d/yjs-src.css",
                // libpath + "cesiumjs/yjs3d/yjs-src.js",

                libpath + "cesiumjs/yjs3d/yjs.css", 
                libpath + "cesiumjs/yjs3d/yjs.js",
                // libpath + "cesiumjs/plugins/navigation/yjs-navigation.css", //导航插件
                // libpath + "cesiumjs/plugins/navigation/yjs-navigation.js"
                //'config/yjsUrl.js' //一些服务地址统一配置
            ]
        };



        for (var i in arrInclude) {
            var key = arrInclude[i];
            inputLibs(libsConfig[key]);
        }

    }

    load();
})();
